package spring.redis;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

@Service
public class RedisService {
 
    @Autowired
    RedisTemplate<String,String> redisTemplate;
    public void testSet(String key,String value){
        redisTemplate.opsForValue().set(key,value);
    }
 
    public String sendMessage (String msg) {
        try {
            redisTemplate.convertAndSend(MessageConstant.AUDIT_LOG_CHANNEL, msg);
            System.out.println(msg);
            return "消息发送成功";
        }catch (Exception e) {
            e.printStackTrace();
            return "消息发送失败";
        }
    }
}